package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.Address;
import br.com.center.loja.ws.dto.AddressDTO;

public class AddressDTOConverter implements Converter<Address, AddressDTO> {
	
	private StreetDTOConverter streetConverter = new StreetDTOConverter();
	
	@Override
	public AddressDTO to(Address element) {
		AddressDTO dto = new AddressDTO(streetConverter.to(element.getDelegate()));
		dto.setNumber(element.getNumber());

		return dto;
	}

	@Override
	public Address from(AddressDTO element) {
		Address address = new Address(streetConverter.from(element.getDelegate()));
		address.setNumber(element.getNumber());
		
		return address;
	}

	@Override
	public List<AddressDTO> to(List<Address> elements) {
		List<AddressDTO> result = new ArrayList<AddressDTO>();
		
		for(Address element : elements){
			result.add(to(element));
		}
		
		return result;
	}

	@Override
	public List<Address> from(List<AddressDTO> elements) {
		List<Address> result = new ArrayList<Address>();
		
		for(AddressDTO element : elements){
			result.add(from(element));
		}
		
		return result;
	}

}
